package engine.systems.update.timer
{
	import ash.core.Component;

	public class Timer extends Component
	{
		public var paused:Boolean = false;
		
		internal var _data:Array = new Array();
		
		public function Timer() { }
		
		override public function destroy():void
		{
			while(this._data.length > 0) this._data.pop().destroy();
			
			this._data = null;
		}
		
		public function add(data:TimerData):Boolean
		{
			if(this._data.indexOf(data) == -1)
			{
				this._data.push(data);
				return true;
			}
			return false;
		}
		
		public function get(name:String):TimerData
		{
			for each(var data:TimerData in this._data)
			{
				if(data.name == name) return data;
			}
			return null;
		}
		
		public function remove(name:String):Boolean
		{
			for(var i:int = this._data.length - 1; i >= 0; --i)
			{
				if(this._data[i].name == name)
				{
					this._data.splice(i, 1);
					return true;
				}
			}
			return false;
		}
	}
}